package com.cdl.maptest;

import com.cdl.statictest.Persion;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class MapDemo3 {
    public static void main(String[] args) {
        Map<Persion,String> map = new TreeMap<>(new Comparator<Persion>() {
            @Override
            public int compare(Persion o1, Persion o2) {
                return o2.getAge()-o1.getAge();
            }
        });

        map.put(new Persion("xt",112,"男"),"k");
        map.put(new Persion("bb",22,"女"),"cc");
        map.put(new Persion("cc",122,"男"),"k");
        map.put(new Persion("dd",223,"女"),"cc");
        map.put(new Persion("ee",112,"男"),"k");
        map.put(new Persion("ff",212,"女"),"cc");

        System.out.println(map);

        for(Map.Entry<Persion,String> entry:map.entrySet()){
            System.out.println(entry.getKey().getName()+": "+ entry.getKey().getAge());
        }



    }
}
